package com.telit.common.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;


/**
 * Create by Chencf on 2022/07/12
 */
public class HttpInterceptor implements ClientHttpRequestInterceptor {
    private static final Logger logger = LoggerFactory.getLogger(HttpInterceptor.class);

    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        if (logger.isDebugEnabled()) {
            logger.debug("请求地址:  {}", request.getURI());
            logger.debug("请求方法:  {}", request.getMethod());
            logger.debug("请求内容:  {}", new String(body));
            logger.debug("请求头:    {}", request.getHeaders());
        }
        return execution.execute(request, body);
    }
}
